package ks.packs.anotherDay;

import android.util.Log;
import net.daum.mobilead.AdConfig;
import net.daum.mobilead.AdHttpListener;

import com.admob.android.ads.AdManager;
import com.admob.android.ads.AdView;
import net.daum.mobilead.MobileAdView;

public class MultipleAd {
	private String countrySO;

	private AdView adViewAdMob;
	private MobileAdView adViewAdam;

	MultipleAd(String pcountrySo, AdView pAdViewAdMob, MobileAdView pAdViewAdam) {
		
		countrySO = pcountrySo;
		adViewAdMob = pAdViewAdMob;
		adViewAdam = pAdViewAdam;
	}
	
	void initAdMob(Boolean Debug) {

		adViewAdam.setVisibility(0);
		adViewAdam.setEnabled(false);

		if (Debug) {
			AdManager
					.setTestDevices(new String[] { "BA4D3015389CCC72A592AF2F860EDD92" });
		}
	}

	void initAdam(Boolean Debug, String adamClientID) {

		adViewAdMob.setVisibility(0);
		adViewAdMob.setEnabled(false);

		AdConfig.setAllowUseOfLocation(true);
		if (!Debug) {
			AdConfig.setClientId(adamClientID);

		} else {
			AdConfig.setClientId("TestClientId");
			String[] dev = { AdConfig.TEST_EMULATOR };
			AdConfig.setTestDevice(dev);
		}

	}

	void displayAdmob() {
		adViewAdMob.requestFreshAd();
	}

	void displayAdam() {

		adViewAdam.setAdListener(new AdHttpListener() {

			public void failedDownloadAd_AdListener(int in_err, String in_errMsg) {
				if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_INTERNET_PERMISSION_DENIED) {
					Log.d("Activity", " add android.permission.INTENER");
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_HTTPFAILED) {
					Log.d("Activity", " HTTP failed : " + in_errMsg);
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_SDKEXCEPTION) {
					Log.d("Activity", " SDK exception : " + in_errMsg);
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_UNKNOWN_CLIENTID) {
					Log.d("Activity", " NO client ID : " + in_errMsg);
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_INVALID_DEVICE) {
					Log.d("Activity", " invalid device : " + in_errMsg);
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_INVALIDAD) {
					Log.d("Activity", " invalid AD : " + in_errMsg);
				} else if (in_err == AdConfig.AD_DOWNLOAD_ERROR.AD_DOWNLOAD_ERROR_WRONGPARAMETER) {
					Log.d("Activity", " wrong parameter : " + in_errMsg);
				}
				if (adViewAdam == null
						|| (adViewAdam != null && !adViewAdam.hasAd())) {
					adViewAdam.setEnabled(false);
				} else {
					adViewAdam.setEnabled(true);
				}

			}

			public void didDownloadAd_AdListener() {
				// TODO Auto-generated method stub

			}
		});

		adViewAdam.setEnabled(true);
	}

	public Boolean isKorea() {
		if (countrySO.compareTo("kr") == 0)
			return true;
		else
			return false;
	}

}
